package cn.learn.mq.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * rabbitmq的链接工具类
 *
 * @author huangyezhan
 * @version 1.0
 * @date 2021年08月21日11:07
 */

public class RabbitMqConnectionUtil {


    public static Channel creatConnection() {
        // 创建连接对象
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("106.53.254.38");
        factory.setUsername("guest");
        factory.setPassword("guest");

        try {
            Connection connection = factory.newConnection();
            return connection.createChannel();
        } catch (IOException | TimeoutException e) {
            e.printStackTrace();
            return null;
        }
    }

}
